from django.db import models
from django.contrib.auth.models import AbstractUser

# Create your models here.
# class user(models.Model):
#     username = models.CharField(max_length = 20,unique = True)
#     password = models.CharField(max_length = 20)
#     mobile = models.CharField(max_length = 11,unique = True)

# 基于Django提供的用户模型进行自定义模型重写,
# 不用继承 models.Model,因为AbstractUser父类AbstractBaseUser继承了models.Model
# AbstractUer 已经存在username和passw字段,不用重新定义,只需定义mobile
class User(AbstractUser):
    mobile = models.CharField(max_length = 11,unique = True)

    # 声明数据库表名
    class Meta:
        db_table = 'tb_users'
        verbose_name = '用户管理'
        verbose_name_plural = verbose_name

    # 定义每个数据对象的显示信息,二不是显示 "object"
    def __str__(self):
        return self.username